<?php
/**
 * ClassName: schedule
 * Description: 问诊医生排班控制器
 * @Author 周昌
 * @Create 2023/12/4 11:44
 */

namespace app;


use epii\server\Args;
use model\ScheduleModel;
use service\admin\HospitalService;
use service\admin\ScheduleService;

class schedule extends base
{
    public function init()
    {
        parent::init();
        $this->accessDenied();
    }
    public function index()
    {
        //登录用户权限判断
        $hospital_id=$this->adminInfo['hospital_id'];
        $data= ScheduleService::getAjaxData($hospital_id);
        $this->assign('data',$data);
        $this->adminUiDisplay();
    }


    public function add_edit()
    {
        $week = Args::params('week/d');
        $today = Args::params('today/d');
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
            $doctor_ids = Args::params('r');
            $res = ScheduleService::addEdit($week,$today,$doctor_ids);
            $res['code']?$this->success($res['msg']):$this->error($res['msg']);
        }
        $this->_as_info = ScheduleService::getScheduleDoctor($this->adminInfo['hospital_id'],$week,$today);
        $this->_as_week =$week;
        $this->_as_today =$today;
        $this->adminUiDisplay();
    }

    /**
     * @return array|false|string
     * @throws \think\Exception
     * @throws \think\db\exception\PDOException
     * 删除
     */
    public function del()
    {
        $id = Args::params('id');
        //todo 判断该事项下是否已经有床位，无则可以删除
        $res = ScheduleService::del($id);
        if ($res['code']) {
            $this->success($res['msg'],'refresh');
        } else {
            $this->error($res['msg']);
        }
    }

}